package com.qadev.appergodic.base;

import com.qadev.appergodic.utils.AutoScreen;
import io.appium.java_client.MobileElement;
import lombok.extern.slf4j.Slf4j;
import org.testng.annotations.Test;

import java.io.IOException;
import java.util.List;

/**
 * Created by wjp on 2019/8/7.
 */
@Slf4j
public class Apptest extends Base{
    private AutoScreen autoScreen =new AutoScreen();
    @Test
    public void allinLogin() throws InterruptedException, IOException {

        String filepath="D:\\zk\\V3.2\\";
        //获取页面元素
        String str= driver.getPageSource();
        System.out.println("=================="+str+"+++++++++++++++++");
        autoScreen.avToXml(filepath,driver);
        String xpath="//*[contains(@resource-id,'iv_close')]";
        String xpath1="//*[contains(@clickable,'true')]";
        String activityname=driver.currentActivity();//当前acticity的名字
        autoScreen.autoSceenAndroid(driver,filepath,xpath1);//点击并截图

        System.out.println(activityname);
        Thread.sleep(2000);
//        List<WebElement> elements =autoScreen.listElements(driver,xpath1,filepath,activityname);
        List<MobileElement> elements =autoScreen.listElements(driver,xpath1);
        for (int i = 0; i < elements.size(); i++) {
            System.out.println("测试的"+elements.get(i));
        }
        autoScreen.skipOldpage(driver);
        List<MobileElement> element2 =autoScreen.listElements(driver,xpath1);
        System.out.println(element2.size());
        for (int i = 0; i < element2.size(); i++) {
            autoScreen.avToXml(filepath,driver);
            System.out.println("测试x"+element2.get(i));
            System.out.println("位置X"+element2.get(i).getLocation().getX()+"位置Y"+element2.get(i).getLocation().getY());
            if(autoScreen.autoSceenAndroid(driver,filepath,element2.get(i),driver.currentActivity()))
                element2.get(i).click();
            autoScreen.skipOldpage(driver);
        }
        // TODO: 2019/8/12 循环点击     
    }


}
